home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_2.lha
/
5_2
/
5_2b1.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
813b
|
40 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ insert a new node to the left, right
/ or at the node pointed to by "head"
include <tree.h>
include <string.h>
tatic void insnode(tnode **parent, char *str)
// a leaf found, enter the node here
if (!*parent)
{
*parent = new tnode(str);
return;
}
// check the name
int cmp = strcmp(str, (*parent)->tword);
// enter in the left subtree
if (cmp < 0)
insnode(&(*parent)->left, str);
// enter in the right subtree
else if (cmp > 0)
insnode(&(*parent)->right, str);
// equal, increment the reference count
else /* if (cmp == 0) */
(*parent)->count++;
/ add a new word to the tree
oid tree:: addnode(char *str)
insnode(&head, str);